/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = frct_detect_hash_del_node.c                        */
/*  NOTE      =                                                    */
/*  DATE      = 2016/04/20 by jikw                                 */
/*******************************************************************/
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "apmtest_comm.h"
#include "frct_detect_hash.h"

#define MODULE_L7PROTO     11211

extern int frct_detect_hash_del_node(Conntrack *p_st_ct, Frlist_node *p_st_node);

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    int i_ret = 0;
    Conntrack *p_st_ct = NULL;
    Frlist_node *p_st_node = NULL;
    
    i_ret = frct_detect_hash_del_node(p_st_ct, p_st_node);
    
    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    return;
}

static void __case2(void)
{
    int i_ret = 0;
    Conntrack *p_st_ct = NULL;
    void *p_detect_data = NULL;
    Frlist_node *p_st_node = NULL;

    p_st_ct = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_ct, 0x00, sizeof(Conntrack));
    p_st_ct->p_st_hash_detect_data = frct_detect_hash_init(256);

    p_detect_data = frmalloc(8);
    frct_detect_hash_add(p_st_ct, MODULE_L7PROTO, p_detect_data);
    
    p_st_node = frct_detect_data_get_node(p_st_ct, MODULE_L7PROTO);
    
    i_ret = frct_detect_hash_del_node(p_st_ct, p_st_node);
    
    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    
    frct_detect_hash_free(&p_st_ct->p_st_hash_detect_data);
    frfree(p_st_ct);

    return;
}

int add_suite_frct_detect_hash_del_node(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frct_comm frct_detect_hash_del_node()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);

    return FR_SUCC;
}
